#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using WaveMaster.Holidays.Club.Service;
using WaveMaster.Holidays.Club.Domain;
using System.Configuration;
using CrystalDecisions.Web;
using CrystalDecisions.CrystalReports.Engine;
using System.Collections;

#endregion

namespace WaveMaster.Holidays.Club.Web
{
    public partial class UserControlReportTicketPurchase : UserControl
    {
        TravelAgentService m_travelAgentService;
        TicketPurchaseService m_ticketPurchaseService;
        User m_currentUser;
        MainForm m_mainForm;

        public UserControlReportTicketPurchase(string name, User user, MainForm mainForm)
        {
            InitializeComponent();
            Name = name;
            m_currentUser = user;
            m_mainForm = mainForm;
            m_ticketPurchaseService = (TicketPurchaseService)ServiceFactory.Instance().GetService(ServiceFactory.TICKET_PURCHASE_SERVICE);
            m_travelAgentService = (TravelAgentService)ServiceFactory.Instance().GetService(ServiceFactory.TRAVEL_AGENT_SERVICE);
            initToolBarClick();
            initComboDataSource();
            comboBoxTravelAgent.Enabled = user.UserType == UserType.Administrators;
            comboBoxTravelAgent.Text = user.TravelAgent.ToString();
        }

        private void initComboDataSource()
        {
            ArrayList tas = new ArrayList();
            tas.Add(new TravelAgent(0, "ALL"));
            tas.AddRange(m_travelAgentService.LoadAllTravelAgent());
            comboBoxTravelAgent.DataSource = tas;
        }

        private void initToolBarClick()
        {
            toolBarButtonRunReport.Click += new EventHandler(toolBarButtonRunReport_Click);
        }

        void toolBarButtonRunReport_Click(object sender, EventArgs e)
        {
            TravelAgent ta = (TravelAgent)comboBoxTravelAgent.SelectedValue;
            DataSet result = m_ticketPurchaseService.ReportTicketPurchaseByDateAndTravelAgent(dateTimePickerFrom.Value, dateTimePickerTo.Value, ta.TravelAgentID);
            result.WriteXml(ConfigurationManager.AppSettings["ReportDataTemp"] + "TicketPurchaseReport" + m_currentUser.UserID + ".xml", XmlWriteMode.WriteSchema);
            htmlBox1.Url = ConfigurationManager.AppSettings["URLReport"] + "ReportViewer.aspx?ReportDataSource=TicketPurchaseReport" + m_currentUser.UserID + ".xml&ReportFile=TicketPurchaseReport.rpt";
            htmlBox1.Update();

            //result.WriteXml(@"D:\Others\Projects\WavemasterHolidaysClub\TicketPurchaseReport.xml", XmlWriteMode.WriteSchema);
        //    string reportID = ServiceFactory.GenerateRandomID().ToString();
        //    Session["ReportTicketPurchaseData" + reportID] = result;
        //    Session["ReportTicketPurchaseFile" + reportID] = "TicketPurchaseReport.rpt";
        //    string param1 = "ReportFile=ReportTicketPurchaseFile" + reportID;
        //    string param2 = "ReportDataSource=ReportTicketPurchaseData" + reportID;
        //    htmlBox1.Url = ConfigurationManager.AppSettings["URLReport"] + "ReportViewer.aspx?" + param1 + "&" + param2;
        //    htmlBox1.Update();
        }
    }
}